<template>
    <div id="logins">
           <header class="header7">
                <a href=""><i class="iconfont">&#xe607;</i></a> 登录
            </header>
            <div class="formbox">
                <div>
                    <input type="text" placeholder="手机/邮箱/用户名" class="username"/>
                </div>
                <div>
                    <input type="password" placeholder="密码" class="password"/>
                    <i class="iconfont icon icon-yanjing1"></i>
                </div>
            </div>
            <button class="submitBtn">登录</button>
            <div class="forgetps">
                没有账号，请先
                <router-link to="/register1">注册</router-link>
                <a href="javascript:;">忘记密码？</a>

            </div>
            <div class="alertbox"></div>
    </div>
</template>

<script>
//引入jQuery
   import $ from 'jquery';

    export default {
        name: 'login',
        data(){
            return{
               list:[]
            }
        },
        methods:{
            
        },
        computed:{

        },
         mounted(){
             var that=this;
            $(".username").val(localStorage.getItem("tel"));
            $(".password").val(localStorage.getItem("pwd"));
            var Icon = $(".icon").get(0);
            var InputNode = $(".password").get(0);
   
            $(".icon").click(function () {
                if ($(InputNode).attr("type") == "password") {
                    $(InputNode).attr("type","text")
                    $(Icon).removeClass("icon-yanjing1").addClass("icon-yanjing");
                } else {
                    $(InputNode).attr("type","password")
                    $(Icon).removeClass("icon-yanjing").addClass("icon-yanjing1");
                }
            })


            $(".submitBtn").click(function(){
            that.$http.post('http://127.0.0.1:2000/api/login',{tel:$(".username").val(),password:$(".password").val()})
            .then(function (res) {
               if(res.body.success==1){
                    sessionStorage.setItem("user_info",JSON.stringify(res.body.result[0]));
                    alert("登录成功");
                    that.$router.push({path:'/islogin'})  //js路由跳转
               }
                
            },function(err){
                console.log(err);
            })
            
        })

        }
    }
</script>